﻿using Data.Video;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc; 
using MvcPaging;

namespace Index.Controllers
{
    public class VideoController : Controller
    {
        //
        // GET: /Video/

        private const int defaultPageSize = 15;
        //
        // GET: /HomeMain/
        private VideoEntities db = new VideoEntities();

        public ActionResult Index(int? id)
        {
            int currentPageIndex = id.HasValue ? id.Value : 1;
            IList<Video> news = db.Video.OrderByDescending(e => e.IdOld).ToList().ToPagedList(currentPageIndex, defaultPageSize);
            return View(news);
        }
        public ActionResult Video(int? id)
        {
            Video video = db.Video.Find(id);
            if (video == null)
            {
                return HttpNotFound();
            }
            return View(video);
        }
        public PartialViewResult Right(int? id)
        {
            ViewBag.lstNew = db.Video.OrderByDescending(e => e.Id).Take(3).ToList();
            ViewBag.lstHot = db.Video.OrderByDescending(e => e.View).ThenByDescending(e => e.Comment).Take(3).ToList();
            ViewBag.lst = (from e in db.Video orderby Guid.NewGuid() select e).Take(18).ToList();

            return PartialView();
        }  

    }
}
